package com.luckycoder.repository.impl;

import com.luckycoder.entity.Student;
import com.luckycoder.repository.StudentRepository;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class StudentRepositoryImpl implements StudentRepository {
    private static final Map<Long, Student> studentMap;
    static {
        studentMap = new HashMap<>();
        studentMap.put(1L, new Student(1L,"张1",11));
        studentMap.put(2L, new Student(2L,"张2",12));
        studentMap.put(3L, new Student(3L,"张3",13));
        studentMap.put(4L, new Student(4L,"张4",14));
        studentMap.put(5L, new Student(5L,"张5",15));
    }

    @Override
    public Collection<Student> findAll() {
        return studentMap.values();
    }

    @Override
    public Student findById(long id) {
        return studentMap.get(id);
    }

    @Override
    public void saveOrUpdate(Student student) {
        studentMap.put(student.getId(), student);
    }

    @Override
    public void delete(long id) {
        studentMap.remove(id);
    }
}
